<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../js/jquery-1.11.3.js"></script>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      .main {
        border: 1px solid white;
        width: 100%;
        height: 500px;
      }
      .login-form {
        position: relative;
        border: 1px solid white;
        width: 288px;
        height: 300px;
        margin: 80px 0 40px 900px;
        background-color: rgba(236, 233, 233, 0.904);
      }
      .login-tab {
        font-size: 30px;
        text-align: center;
        margin-top: 30px;
        color: red;
      }
      .login-txt {
        width: 260px;
        margin-bottom: 20px;
      }
      .from {
        width: 270px;
        height: 180px;
        padding: 10px;
        margin-top: 20px;
      }
      label {
        display: inline-block;
        width: 50px;
        text-align: center;
        font-size: 14px;
      }
      input {
        height: 20px;
        outline: none;
        padding: 5px 10px;
        font-size: 14px;
      }
      .login-btn {
        width: 270px;
        margin-top: 20px;
      }
      .login-btn button {
        cursor: pointer;
        border: none;
        width: 100%;
        height: 35px;
        background-color: red;
        color: white;
        text-align: center;
        line-height: 30px;
        font-size: 20px;
      }
      .tz {
        position: absolute;
        bottom: 30px;
        text-decoration: none;
        font-size: 12px;
        right: 0;
        color: red;
      }
      .login_logo {
        width: 1200px;
        height: 60px;
        margin: 0 auto;
      }
      .login_logo a {
        vertical-align: middle;
        float: left;
      }
      .login_logo h1 {
        margin-top: 10px;
        float: left;
        height: 60px;
        line-height: 60px;
        vertical-align: middle;
        margin-left: 20px;
        font-size: 26px;
        color: #666;
      }
      .login-banner {
        width: 100%;
        height: 475px;
        background-color: #e93854;
        position: absolute;
        left: 0;
        top: 70px;
      }
      .l_pic {
        height: 100%;
        position: absolute;
        width: 990px;
        left: 300px;
        background: url(https://passport.jd.com/new/misc/2015/background.png);
        background-position: 0 0;
        background-repeat: no-repeat;
      }
    </style>
  </head>
  <body>
    <div class="main">
      <div class="login_logo">
        <a>
          <img
            src="https://misc.360buyimg.com/lib/img/e/logo-201305-b.png"
            alt=""
          />
        </a>
        <h1>欢迎登录</h1>
      </div>
      <div class="login-banner">
        <div class="l_pic"></div>
      </div>
      <div class="login-form">
        <div class="login-tab">会员账号登录</div>
        <form class="from" onsubmit="return false">
          <div class="login-txt">
            <label for="">用户名:</label>
            <input type="text" placeholder="用户名" name="username" />
          </div>
          <div class="login-psw">
            <label for="">密码:</label>
            <input type="password" placeholder="密码" name="password" />
          </div>
          <div class="login-btn">
            <button id="btn">登&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;录</button>
          </div>
        </form>
        <a href="register.html" class="tz">没有账号去注册</a>
      </div>
    </div>
    <script>
      $(function () {
        $(".from").on("submit", function () {
          let data = $(".from").serialize();
          //console.log(data);
          $.get("http://jx.xuzhixiang.top/ap/api/login.php", data, (res) => {
            if (res.code === 0) {
              alert("请检查用户名和密码");
              return;
            } else {
              localStorage.setItem("id", res.data.id);
              localStorage.setItem("token", res.data.token);
              localStorage.setItem("username", res.data.username);
              alert("登录成功");
              location.href = "./index.html";
            }
            console.log(res);
          });
        });
      });
    </script>
  </body>
</html>
